<template>
    <div>
        <el-card>
            <el-breadcrumb separator="/">
                <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
                <el-breadcrumb-item>销售工具</el-breadcrumb-item>
                <el-breadcrumb-item>采购入库</el-breadcrumb-item>
            </el-breadcrumb>

            <div class="btnBox">
                <el-button type="primary" size="small" @click="addHandle">采购入库</el-button>
            </div>

            <el-table :data="stockList" border style="width: 100%" height="620"
                :header-cell-style="{ background: '#409EFF', color: '#FFF' }">
                <el-table-column prop="intoId" label="编号" width='80'></el-table-column>
                <el-table-column prop="intoDate" label="业务日期"></el-table-column>
                <el-table-column prop="handelName" label="采购人"></el-table-column>
                <el-table-column prop="productNum" label="商品数量"></el-table-column>
                <el-table-column prop="productTotal" label="采购总金额"></el-table-column>
                <el-table-column prop="productStatus" label="状态">
                    <template slot-scope="scope">
                        <el-tag type="success" v-if="scope.row.applyStatus == 1">已审核</el-tag>
                        <el-tag type="danger" v-else>未审核</el-tag>
                    </template>
                </el-table-column>
                <el-table-column prop="intoNote" label="备注"></el-table-column>
                <el-table-column label="操作" width='200'>
                    <template slot-scope="scope">
                        <el-button size="small" @click="applyHandle(scope.row, 1)" v-if="scope.row.applyStatus == 0"
                            plain>审核</el-button>
                        <el-button size="small" @click="checkHandle(scope.row)" plain>查看详情</el-button>
                    </template>
                </el-table-column>
            </el-table>

            <div class="paginationBox">
                <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
                    :current-page="pageNum" :page-sizes="[20, 50, 100]" :page-size="pageSize"
                    layout="total, sizes, prev, pager, next, jumper" :total="total">
                </el-pagination>
            </div>


            <el-dialog title="采购入库" :visible.sync="dialogVisible" width="1200px" border>
                <el-form :model="form">
                    <div class="row-style mbtm12">
                        <el-form-item label="操作人">
                            <el-select v-model="form.handelName" placeholder="请选择">
                                <el-option v-for="item in preparerList" :key="item.userId"
                                    :value="item.userName"></el-option>
                            </el-select>
                        </el-form-item>
                        <div class="addTip" @click="addOtherHandle('preparer')">点击新增操作人</div>
                    </div>
                    <el-form-item label="备注">
                        <el-input v-model="form.intoNote" type="textarea" placeholder="请输入备注" />
                    </el-form-item>

                    <el-form-item>
                        <el-button @click="addProduct" class="add-btn">新增</el-button>
                        <el-button @click="delProduct">删除</el-button>
                    </el-form-item>
                    <el-table :data="form.list" tooltip-effect="dark" @selection-change="handleSelectionChange">
                        <el-table-column type="selection"></el-table-column>
                        <el-table-column prop="productId" label="商品编号"></el-table-column>
                        <el-table-column prop="productName" label="商品名称"></el-table-column>
                        <el-table-column prop="formatName" label="规格"></el-table-column>
                        <el-table-column prop="itemUnit" label="单位"></el-table-column>
                        <el-table-column prop="barCode" label="批号"></el-table-column>
                        <el-table-column prop="productSate" label="生产日期" width="120"></el-table-column>
                        <el-table-column prop="validity" label="有效期"></el-table-column>
                        <el-table-column prop="warehouseName" label="仓库"></el-table-column>
                        <el-table-column prop="factoryName" label="厂商"></el-table-column>
                        <el-table-column prop="productNum" label="数量"></el-table-column>
                        <el-table-column prop="productPrice" label="价格"></el-table-column>
                        <el-table-column prop="productTotal" label="总金额"></el-table-column>
                    </el-table>
                </el-form>
                <div slot="footer" class="dialog-footer">
                    <el-button @click="handleClose">取 消</el-button>
                    <el-button type="primary" @click="submitHandle">确 定</el-button>
                </div>
            </el-dialog>



            <el-dialog title="新增商品" :visible.sync="proAddDialog" width="720px">
                <el-form :model="stockItem" ref="refForm">
                    <div class="row-style">
                        <el-form-item label="商品名称">
                            <el-select v-model="stockItem.productId" placeholder="请选择" filterable @change="getFormat">
                                <el-option v-for="item in productList" :key="item.productId" :label="item.productName"
                                    :value="item.productId">
                                </el-option>
                            </el-select>
                        </el-form-item>
                        <div class="addTip" @click="addOtherHandle('product')">点击新增商品</div>
                    </div>
                    <div class="row-style">
                        <el-form-item label="批号">
                            <el-input v-model="stockItem.barCode" placeholder="请输入批号"></el-input>
                        </el-form-item>
                        <el-form-item label="单位">
                            <el-select v-model="stockItem.itemUnit" placeholder="请选择">
                                <el-option label="个" value="个"></el-option>
                                <el-option label="瓶" value="瓶"></el-option>
                                <el-option label="盒" value="盒"></el-option>
                                <el-option label="桶" value="桶"></el-option>
                                <el-option label="台" value="台"></el-option>
                                <el-option label="箱" value="箱"></el-option>
                            </el-select>
                        </el-form-item>
                    </div>
                    <div class="row-style">
                        <el-form-item label="仓库">
                            <el-select v-model="stockItem.warehouseId" placeholder="请选择">
                                <el-option v-for="item in warehouseList" :key="item.warehouseId"
                                    :label="item.warehouseName" :value="item.warehouseId">
                                </el-option>
                            </el-select>
                        </el-form-item>
                        <div class="addTip" @click="addOtherHandle('warehouse')">点击添加仓库</div>
                    </div>
                    <div class="row-style">
                        <el-form-item label="生产日期" prop="productSate">
                            <el-date-picker type="date" value-format="yyyy-MM-dd" placeholder="选择生产日期"
                                v-model="stockItem.productSate" style="width: 200px;"></el-date-picker>
                        </el-form-item>
                        <el-form-item label="效期" prop="validity">
                            <el-input v-model="stockItem.validity" placeholder="请输入效期"></el-input>
                        </el-form-item>
                    </div>
                    <div class="row-style">
                        <el-form-item label="数量">
                            <el-input type="number" v-model="stockItem.productNum" placeholder="请输入采购数量"
                                @input='proInput'></el-input>
                        </el-form-item>
                        <el-form-item label="销售价">
                            <el-input v-model="stockItem.productPrice" autocomplete="off" placeholder="请输入销售价"
                                @input='proInput'></el-input>
                        </el-form-item>
                    </div>
                    <div class="row-style">
                        <el-form-item label="总金额">
                            <el-input v-model="stockItem.productTotal" readonly placeholder="总金额"></el-input>
                        </el-form-item>
                    </div>
                </el-form>
                <div slot="footer" class="dialog-footer">
                    <el-button @click="proDiaClose">取 消</el-button>
                    <el-button type="primary" @click="sureProduct">确 定</el-button>
                </div>
            </el-dialog>


            <el-dialog title="入库详情" :visible.sync="detailDia" width="60%" top="4%" :before-close="detailHandleClose">
                <el-table :data="detailList" border style="width: 100%" height="520">
                    <el-table-column prop="productName" label="商品名称"></el-table-column>
                    <el-table-column prop="formatName" label="规格"></el-table-column>
                    <el-table-column prop="barCode" label="批号"></el-table-column>
                    <el-table-column prop="productSate" label="生产日期"></el-table-column>
                    <el-table-column prop="validity" label="有效期"></el-table-column>
                    <el-table-column prop="factoryName" label="厂商"></el-table-column>
                    <el-table-column prop="warehouseName" label="仓库"></el-table-column>
                    <el-table-column prop="productPrice" label="单价"></el-table-column>
                    <el-table-column prop="itemUnit" label="单位"></el-table-column>
                    <el-table-column prop="productNum" label="数量"></el-table-column>
                    <el-table-column label="总金额">
                        <template slot-scope="scope">
                            {{ scope.row.productTotal.toFixed(2) }}
                        </template>
                    </el-table-column>
                </el-table>
                <div class="paginationBox">
                    <el-pagination @size-change="dHandleSizeChange" @current-change="dHandleCurrentChange"
                        :current-page="dPageNum" :page-sizes="[20, 50, 100]" :page-size="dPageSize"
                        layout="total, sizes, prev, pager, next, jumper" :total="dTotal">
                    </el-pagination>
                </div>
            </el-dialog>
            <el-dialog title="添加" :visible.sync="preparerDia" width="30%" top="4%">
                <template v-if="addFlag == 'preparer'">
                    <el-form :model="preparerForm" :rules="preparerRules" ref="preparerForm" label-width="100px"
                        class="demo-ruleForm">
                        <el-form-item label="操作人名称" prop="preparerName">
                            <el-input v-model="preparerForm.preparerName" placeholder="请输入操作人名称"></el-input>
                        </el-form-item>
                    </el-form>
                </template>

                <template v-if="addFlag == 'product'">
                    <el-form :model="productForm" :rules="productRules" ref="productForm" label-width="100px"
                        class="demo-ruleForm">
                        <el-form-item label="商品主图">
                            <el-upload action="aa" class="avatar-uploader" :on-change="proChange" :auto-upload="false"
                                accept="*" ref="addProduct_pic" :show-file-list="false">
                                <template v-if="productForm.product_pic || productForm.imageUrl">
                                    <img :src="productForm.imageUrl" class="avatar" />
                                    <div class="addTip">点击更换图片</div>
                                </template>
                                <i v-else class="el-icon-plus avatar-uploader-icon"></i>
                            </el-upload>
                        </el-form-item>
                        <el-form-item label="商品名称" prop="productName">
                            <el-input v-model="productForm.productName" placeholder="请输入商品名称"></el-input>
                        </el-form-item>
                        <el-form-item label="规格名称" prop="formatName">
                            <el-input v-model="productForm.formatName" placeholder="请输入规格名称"></el-input>
                        </el-form-item>
                        <el-form-item label="厂商" prop="factoryId">
                            <el-select v-model="productForm.factoryId" placeholder="请选择">
                                <el-option v-for="item in factoryList" :key="item.factoryId" :label="item.factoryName"
                                    :value="item.factoryId">
                                </el-option>
                            </el-select>
                            <div class="addTip" @click="addOtherHandle('factory')">点击新增厂商</div>
                        </el-form-item>
                    </el-form>
                </template>


                <template v-if="addFlag == 'warehouse'">
                    <el-form :model="wareHouseForm" :rules="wareHouseRules" ref="wareHouseForm" label-width="100px"
                        class="demo-ruleForm">
                        <el-form-item label="仓库名称" prop="warehouseName">
                            <el-input v-model="wareHouseForm.warehouseName" placeholder="请输入仓库名称"
                                style="width: 220px;"></el-input>
                        </el-form-item>
                    </el-form>
                </template>


                <span slot="footer" class="dialog-footer">
                    <el-button @click="diaHandleClose">取 消</el-button>
                    <el-button type="primary" @click="diaSubmitHandle">确 定</el-button>
                </span>
            </el-dialog>




            <el-dialog title="添加厂商" :visible.sync="facDia" width="20%" top="4%" :before-close="facHandleClose">
                <el-form :model="facForm" :rules="facRules" ref="facForm" label-width="100px" class="demo-ruleForm">
                    <el-form-item label="厂商名称" prop="factoryName">
                        <el-input v-model="facForm.factoryName" placeholder="请输入厂商名称"></el-input>
                    </el-form-item>
                </el-form>
                <span slot="footer" class="dialog-footer">
                    <el-button @click="facHandleClose">取 消</el-button>
                    <el-button type="primary" @click="facSubmitHandle">确 定</el-button>
                </span>
            </el-dialog>



        </el-card>
    </div>
</template>
<script>

import { addInStock, getInStock, getInStockItem, applyInStockItem } from '../../network/intoStock'

import { getSaleUser, addSaleUser } from '../../network/preparer'

import { addFactory, getFactoryByName } from '../../network/factory'

import { listWarehouse, addWarehouse, getCompanylist } from '../../network/warehouse'

import { addProduct, listProductAll } from '../../network/product'


export default {
    name: 'product',
    data() {
        return {
            stockList: [],
            dialogVisible: false,
            form: {
                applyStatus: 0,
                companyId: sessionStorage.companyId,
                handelName: "",
                intoNote: "",
                list: [],
                productNum: 0,
                productTotal: 0
            },
            rules: {
                customerName: [
                    { required: true, message: '请输入客户名称', trigger: 'blur' },
                ],
            },
            pageNum: 1,
            pageSize: 20,
            total: 0,
            searchName: '',
            detailDia: false,//销售详情 弹窗
            detailList: [],// 销售详情
            dPageNum: 1,
            dPageSize: 20,
            dTotal: 0,
            selectItem: '',

            preparerList: [],//操作人
            factoryList: [],// 厂商列表
            warehouseList: [],// 仓库列表
            productList: [],// 商品列表

            proAddDialog: false,//新增商品

            stockItem: { //新增商品信息
                companyId: sessionStorage.companyId,
                productId: '',
                productImg: '',
                productName: '',
                formatName: '',
                productNum: '',
                barCode: '',
                warehouseId: '',
                warehouseName: '',
                factoryId: '',
                factoryName: '',
                itemUnit: '',
                productPrice: '',
                productTotal: '',

                productSate: '',
                validity: '',
            },
            preparerDia: false,
            preparerForm: {
                preparerName: ''
            },
            preparerRules: {
                preparerName: [
                    { required: true, message: '请输入操作人名称', trigger: 'blur' },
                ],
            },


            productForm: {
                productName: '',
                formatName: '',
                factoryName: '',
                imageUrl: '',
                product_pic: '',
                companyId: sessionStorage.companyId,
                productStatus: 1,
                categoryId: 1,
                factoryId: '',
            },
            productRules: {
                productName: [
                    { required: true, message: '请输入商品名称', trigger: 'blur' },
                ],
                formatName: [
                    { required: true, message: '请输入商品规格名称', trigger: 'blur' },
                ],
                factoryId: [
                    { required: true, message: '请选择厂商', trigger: 'change' },
                ],
            },

            addFlag: '',//   添加操作人和商品
            currentList: [],//选择删除的商品


            facDia: false,
            facForm: {
                factoryName: '',
            },
            facRules: {
                factoryName: [
                    { required: true, message: '请输入厂商名称', trigger: 'blur' },
                ],
            },

            companyList: [],

            wareHouseForm: {
                warehouseName: '',
                warehouseStatus: 1,
                companyId: ''
            },
            wareHouseRules: {
                warehouseName: [
                    { required: true, message: '请输入仓库名称', trigger: 'blur' },
                ],
                companyId: [
                    { required: true, message: '请输入选择公司', trigger: 'change' },
                ],
            },
        }
    },
    created() {
        this.getList()


    },
    methods: {
        // 添加操作人  商品
        addOtherHandle(flag) {
            if (flag == 'factory') {
                this.facDia = true
            } else {
                this.addFlag = flag
                this.preparerDia = true
            }
        },
        diaHandleClose() {
            this.preparerDia = false
            if (this.addFlag == 'preparer') {
                this.preparerForm = {
                    preparerName: ''
                }
            } else if (this.addFlag == 'product') {
                this.productForm = {
                    productName: '',
                    formatName: '',
                    factoryName: '',
                    imageUrl: '',
                    product_pic: '',
                    companyId: sessionStorage.companyId,
                    productStatus: 1,
                    categoryId: 1,
                    factoryId: '',
                }
            } else if (this.addFlag == 'warehouse') {
                this.wareHouseForm = {
                    warehouseName: '',
                    warehouseStatus: 1,
                    companyId: ''
                }
                this.$refs.wareHouseForm.resetFields()


            }
        },
        // 添加厂商
        facSubmitHandle() {
            this.$refs.facForm.validate((valid) => {
                console.log(valid);

                if (!valid) return

                console.log(this.facForm);

                addFactory({
                    factoryName: this.facForm.factoryName,
                    factoryStatus: 1,
                    companyId: sessionStorage.companyId
                }).then(res => {
                    console.log(res);
                    if (res.flag) {
                        this.getFactoryList();
                        this.facHandleClose();
                        this.$message.success("添加成功");
                    } else {
                        console.log(res);
                        this.$message.success("添加失败");
                    }
                });
            });


        },
        facHandleClose() {
            this.facDia = false
            this.$refs.facForm.resetFields()
        },

        // 确认弹窗
        diaSubmitHandle() {
            if (this.addFlag == 'preparer') {
                this.$refs.preparerForm.validate((valid) => {
                    console.log(valid);
                    if (!valid) return
                    addSaleUser({
                        userName: this.preparerForm.preparerName,
                        userStatus: 1,
                        userTag: -1
                    }).then(res => {
                        console.log(res);
                        if (res.flag) {
                            this.getuserList();
                            this.diaHandleClose('preparer');
                            this.$message.success("添加成功");
                        } else {
                            console.log(res);
                            this.$message.success("添加失败");
                        }
                    });
                });
            } else if (this.addFlag == 'product') {
                this.$refs.productForm.validate((valid) => {
                    console.log(valid);

                    if (!valid) return

                    console.log(this.productForm);

                    if (this.productForm.product_pic == '') {
                        this.$message.warning('请上传商品图片')
                        return
                    }

                    console.log(this.productForm.product_pic);
                    console.log(this.productForm);


                    this.factoryList.forEach(ele => {
                        if (ele.factoryId == this.productForm.factoryId) {
                            this.productForm.factoryName = ele.factoryName
                        }
                    })

                    console.log(this.productForm);

                    // return

                    var formData = new FormData();
                    formData.append("file", this.productForm.product_pic);
                    formData.append("productName", this.productForm.productName);
                    formData.append("formatName", this.productForm.formatName);
                    formData.append("factoryName", this.productForm.factoryName);
                    formData.append("companyId", this.productForm.companyId);
                    formData.append("productStatus", this.productForm.productStatus);
                    formData.append("categoryId", this.productForm.categoryId);

                    addProduct(formData).then(res => {
                        console.log(res);
                        if (res.flag) {
                            this.getProductList();
                            this.diaHandleClose();
                            this.dialogVisible = false
                            this.$message.success("上传成功");
                        } else {
                            console.log(res);
                            this.$message.success("上传失败");
                        }
                    });
                });
            } else if (this.addFlag == 'warehouse') {

                this.$refs.wareHouseForm.validate((valid) => {
                    if (!valid) return;
                    addWarehouse(
                        {
                            warehouseName: this.wareHouseForm.warehouseName,
                            warehouseStatus: this.wareHouseForm.warehouseStatus,
                            companyId: sessionStorage.companyId
                        })
                        .then(response => {
                            console.log(response);
                            this.diaHandleClose()
                            this.getWarehouseList();
                        })
                        .catch(error => {
                            console.error('添加仓库失败', error);
                        });
                });


            }
        },

        proChange(file) {
            this.productForm.imageUrl = URL.createObjectURL(file.raw);
            this.productForm.product_pic = file.raw;
        },
        getFormat() {
            this.productList.forEach(ele => {
                if (ele.productId == this.stockItem.productId) {
                    this.stockItem.productImg = ele.productImg
                    this.stockItem.productName = ele.productName
                    this.stockItem.formatName = ele.formatName
                    this.stockItem.factoryName = ele.factoryName
                }
            })

            console.log(this.stockItem);

        },
        proInput() {
            if (this.stockItem.productNum != '' && this.stockItem.productNum != '') {
                this.stockItem.productTotal = Number(this.stockItem.productNum) * Number(this.stockItem.productPrice)
            }
        },
        // 确认添加商品
        sureProduct() {

            if (this.stockItem.productId == '') {
                this.$message.warning('请选择采购的商品')
                return
            }
            if (this.stockItem.barCode == '') {
                this.$message.warning('请输入批号')
                return
            }
            if (this.stockItem.itemUnit == '') {
                this.$message.warning('请选择单位')
                return
            }
            if (this.stockItem.warehouseId == '') {
                this.$message.warning('请选择仓库')
                return
            }
            if (this.stockItem.productSate == '') {
                this.$message.warning('请选择生产日期')
                return
            }
            if (this.stockItem.validity == '') {
                this.$message.warning('请输入有效期')
                return
            }
            if (this.stockItem.productNum == '' || this.stockItem.productNum == 0) {
                this.$message.warning('请输入采购数量')
                return
            }
            if (this.stockItem.productPrice == '' || this.stockItem.productPrice == 0) {
                this.$message.warning('请输入采购价格')
                return
            }


            this.warehouseList.forEach(ele => {
                if (ele.warehouseId == this.stockItem.warehouseId) {
                    this.stockItem.warehouseName = ele.warehouseName
                }
            })

            this.factoryList.forEach(ele => {
                if (ele.factoryName == this.stockItem.factoryName) {
                    this.stockItem.factoryId = ele.factoryId
                }
            })


            console.log(this.stockItem);

            this.form.list.push(JSON.parse(JSON.stringify(this.stockItem)))


            this.proDiaClose()

        },


        proDiaClose() {
            this.proAddDialog = false
            this.$refs.refForm.resetFields()
            this.stockItem = {
                companyId: sessionStorage.companyId,
                productId: '',
                productImg: '',
                productName: '',
                formatName: '',
                productNum: '',
                barCode: '',
                warehouseId: '',
                warehouseName: '',
                factoryId: '',
                factoryName: '',
                itemUnit: '',
                productPrice: '',
                productTotal: '',
                productSate: '',
                validity: '',
            }
        },

        addProduct() {
            this.proAddDialog = true

            console.log(this.productList);

        },
        delProduct() {


            if (this.currentList.length == 0) {
                this.$message.info("请选择删除项");
                return false;
            }
            var len = [];
            this.currentList.forEach(item => {
                this.form.list.forEach((pro, index) => {
                    if (item.productId == pro.productId && item.barCode == pro.barCode) {
                        len.push(index);
                    }
                })
            })
            var currentLists = this.form.list;
            for (var i = 0; i < len.length; i++) {
                currentLists.splice(len[i], 1);
            }
            this.form.list = currentLists;

        },

        handleSelectionChange(val) {
            this.currentList = val;
            console.log(this.currentList);

        },
        applyHandle(obj) {
            this.$confirm('是否通过入库审核?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
            }).then(() => {
                applyInStockItem({
                    intoId: obj.intoId
                }).then(res => {
                    if (res.flag) {
                        this.getList()
                        this.$message.success('审核成功')
                    } else {
                        this.$message.warning('审核失败')
                    }
                })
            }).catch(() => {
            });

        },

        checkHandle(obj) {
            this.selectItem = obj
            getInStockItem({
                intoId: obj.intoId,
                pageNum: this.pageNum,
                pageSize: this.pageSize,
            }).then(res => {
                if (res.flag) {
                    console.log(res);
                    this.detailList = res.data.list
                    this.dTotal = res.data.total
                    this.detailDia = true
                }
            })
        },


        submitHandle() {


            if (this.form.handelName == '') {
                this.$message.warning('请选择操作人')
                return
            }

            if (this.form.list.length == 0) {
                this.$message.warning('请选择入库商品')
                return
            }

            this.form.productNum = 0
            this.form.productTotal = 0


            this.form.list.forEach(ele => {
                this.form.productNum += Number(ele.productNum)
                this.form.productTotal += Number(ele.productTotal)
            })



            console.log(this.form);

            addInStock(this.form).then(res => {
                console.log(res);
                if (res.flag) {
                    this.getList();
                    this.handleClose();
                    this.dialogVisible = false
                    this.$message.success("操作成功");
                } else {
                    console.log(res);
                    this.$message.success("操作失败");
                }
            });


        },
        addHandle() {
            this.dialogVisible = true
            this.getuserList()
            this.getWarehouseList()
            this.getFactoryList()
            this.getProductList()
        },
        handleClose() {
            this.dialogVisible = false
            this.form = {
                applyStatus: 0,
                companyId: sessionStorage.companyId,
                handelName: "",
                intoNote: "",
                list: [],
                productNum: 0,
                productTotal: 0
            }
        },

        detailHandleClose() {
            this.detailDia = false
        },

        getList() {
            getInStock({
                pageNum: this.pageNum,
                pageSize: this.pageSize,
                companyId: sessionStorage.companyId,
            }).then(res => {
                if (res.flag) {
                    console.log(res);
                    this.stockList = res.data.list
                    this.total = res.data.total
                }
            })
        },

        handleSizeChange(val) {
            this.pageSize = val
            this.getList()
        },
        handleCurrentChange(val) {
            this.pageNum = val
            this.getList()
        },
        dHandleSizeChange(val) {
            this.dPageSize = val
            this.checkHandle(this.selectItem)
        },
        dHandleCurrentChange(val) {
            this.dPageNum = val
            this.checkHandle(this.selectItem)
        },
        searchHandle() {
            this.pageNum = 1
            this.pageSize = 20
            this.getList()
        },
        clearInput() {
            this.pageNum = 1
            this.pageSize = 20
            this.getList()
        },

        getuserList() {
            getSaleUser({
                companyId: sessionStorage.companyId,   //  进销存人员传  id  广告牌传0
                flag: 0  //  0 进销存查询人员  1 广告牌查询人员
            }).then(res => {
                if (res.flag) {
                    console.log(res);
                    this.preparerList = res.data.filter(item => {
                        return item.userStatus == 1 && item.userTag == -1
                    })
                }
            })
        },

        getFactoryList() {
            getFactoryByName({
                pageNum: 1,
                pageSize: 100,
                factoryName: '',
                companyId: sessionStorage.companyId
            }).then(res => {
                if (res.flag) {
                    console.log(res);
                    this.factoryList = res.data.list.filter(item => {
                        return item.factoryStatus == 1
                    })
                }
            })
        },

        getWarehouseList() {
            listWarehouse({
                pageNum: 1,
                pageSize: 100,
                warehouseName: '',
                companyId: sessionStorage.companyId
            })
                .then(res => {
                    if (res.flag) {
                        this.warehouseList = res.data.list.filter(item => {
                            return item.warehouseStatus == 1
                        });
                    }
                })
                .catch(error => {

                });
        },

        getProductList() {
            listProductAll({
                companyId: sessionStorage.companyId
            }).then(res => {
                if (res.flag) {
                    console.log(res);
                    this.productList = res.data.filter(item => {
                        return item.productStatus == 1
                    })
                }
            })
        },

        // getCompany() {
        //     const PageInfo = {
        //         pageNum: 1,
        //         pageSize: 50
        //     };
        //     getCompanylist(PageInfo)
        //         .then(res => {
        //             if (res.flag) {
        //                 this.companyList = res.data.list;
        //             }
        //         })
        //         .catch(error => {
        //             console.error('获取公司列表失败', error);
        //         });
        // }

    }
}
</script>

<style lang="less" scoped>
.paginationBox {
    margin-top: 20px;
    display: flex;
    justify-content: flex-end;
}


.avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
}

.avatar-uploader .el-upload:hover {
    border-color: #409eff;
}

.avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 100px;
    height: 100px;
    line-height: 100px;
    text-align: center;
    border: 1px dashed #dcdfe6;
    border-radius: 8px;
}

.image-control {
    display: block;
    border-radius: 8px;
    width: 100px;
    height: 100px;
}

.input-with-select {
    margin-left: 15px;
    width: 300px;
}

.btnBox {
    display: flex;
    align-items: center;
    margin-top: 15px;
}

.row-style {
    display: flex;
    align-items: center;
}

.row-style /deep/ .el-form-item {
    display: flex;
    margin-right: 26px;
}

.row-style /deep/ .el-form-item__label {
    text-align: left;
    width: 68px;

}

.none /deep/ .el-form-item__label {
    width: 58px;
}

.add-btn {
    background-color: #409eff;
    color: #fff;
    border: 1px solid #409eff;
}

.row-style /deep/ .el-input {
    width: 200px;
}

.tipBox {
    color: red;
    font-size: 14px;
}


.addTip {
    color: #409eff;
    text-decoration: underline;
    cursor: pointer;
}


.avatar {
    display: block;
    border-radius: 8px;
    width: 100px;
    height: 100px;
}
</style>